<?php
namespace Home\Controller;
use Common\Lib\User;
use Home\Model\DepartmentModel;
use Home\Model\RoleModel;

class PersonnelPerformanceController extends CommonController {
	protected $table="RecruitInfo";
	protected $pageSize = 13;


	public function index (){
		$D = D('RbacUser');
		 //获取所有CRM部门 (一维)
        $getalldepartmentsList_url = "Department/getAllDepartmentsList";
	    $alldepartmentsList = json_decode(http_get($getalldepartmentsList_url),true);
        //获取所有CRM部门 (二维)
        $getalldepartments_url = "Department/getAllDepartments";
	    $alldepartments = json_decode(http_get($getalldepartments_url),true);

		$this->assign("roleList", $this->getRoles());
		$this->assign("groupList", D('Group')->where(array('status'=>1))->select());
		$this->assign("sexType", array("未定义", "男", "女"));
		$ename = $this->getRoleEname();
		/*echo 'sss';
		print_r($ename);
		echo 'kkk';*/
    	$this->assign('viewDecorator', D("Department")->decoratorView($ename));

    	//部门选项权限
    	$ename=$this->getRoleEname();

      
    	$this->assign('depart_id', $this->getDepartmentId());
    	$this->assign('departmentItem', $this->setEmployeeDepartemtnItem());
    	$this->assign('allRoles', D('Role')->getField('id,name', true));
       /* 我加的 开始*/
    	$this->assign("userNames", D("User")->getUserNames());
    	$this->assign("departmentNames", D("Department")->getDepartmentsNames());
    	$this->assign("sexType", array("未定义", "男", "女"));
    	$this->assign("sourcesType", array("1"=>"58同城", "2"=>"赶集", "3"=>"智联", "4"=>"前程", "5"=>"校招", "6"=>"介绍", "7"=>"其他"));
    	$this->assign('departments', D('Department')->getAllDepartments('id,name'));
    	$this->assign("sourcesList", $D->getSources(array("1"=>"58同城", "2"=>"赶集", "3"=>"智联", "4"=>"前程", "5"=>"校招", "6"=>"介绍", "7"=>"其他")));
    	$this->assign("allTypes", array("1"=>"初试已过", "2"=>"初试未过", "3"=>"复试已过", "4"=>"复试未过", "5"=>"内部推荐"));
    	$this->assign("typeList", $D->getSources(array("1"=>"初试已过", "2"=>"初试未过", "3"=>"复试已过", "4"=>"复试未过", "5"=>"内部推荐")));
    	$this->assign('user_role_id', session('account')['userInfo']['role_id']);
    	$this->assign('user_department_id', session('account')['userInfo']['department_id']);
    	//获取crm的部门，职能 start
    	$this->assign('allDepartmentsList',$alldepartmentsList["list"]);//一维
    	$this->assign('allDepartments',$alldepartments["list"]);//二维
    	/* 我加的 结束*/
		$this->display();
	}



	public function getList() {
			$user_id = session('account')['userInfo']['user_id'];
			$user_department_id =  session('account')['userInfo']['department_id'];
		/*	echo 'ss';
			print_r(session('account')['userInfo']);
			echo 'kk';*/
			$project = I('get.project');
		    $start = I('get.start');
            $money = I('get.money');
            $plan_num = I('get.plan_num');
			$department_id = I('get.department_id');
			if($money<0  || $plan_num<0){
				$this->error("输入的项目总金额或招聘人数不能为负数，也不能为零！");
			    exit();
			}
			switch(session('account')['userInfo']['role_id']){
				case 18:
				if($project ==1){
					if(empty($start) || empty($money) || empty($plan_num) ){
						$result="";
						$this->error("方案一中绩效月份,项目总金额,计划招聘人数必填！");
						exit;
					}
					if(!empty($department_id)){
							if($department_id != 22){
								$result ="";
								$this->error("方案一只用来考核人资中心(即人事部)！");
								exit;
							}
							//每月的入职人数
						$entry_num = M("RecruitInfo")->where(array('entry_date'=>array('like', I('get.start')."%"),'department_id'=>$department_id))
						->group("user_id")
						->getField('user_id,count(id) as count', true);
						//每月的留用人数
						$retention_num = M("RecruitInfo")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'department_id'=>$department_id))
	                     ->group("user_id")
	                     ->getField('user_id, count(id) as count',true);

					}else{
						if(empty($start) || empty($money) || empty($plan_num)  ){
							$result="";
							exit;
						}
						//每月的入职人数
						$entry_num = M("RecruitInfo")->where(array('entry_date'=>array('like', I('get.start')."%"),'department_id'=>array('eq', 22),'status'=>array('in', '1,2')))
						->group("user_id")
						->getField('user_id,count(id) as count', true);
						//每月的留用人数
						$retention_num = M("RecruitInfo")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'department_id'=>array('eq', 22)))
	                     ->group("user_id")
	                     ->getField('user_id, count(id) as count',true);
					}

						$a = 0;
						$count=0;
						foreach($entry_num as $k=>$v){
							$retention_num["$k"] = empty($retention_num["$k"])?0:$retention_num["$k"];
							$retention = $retention_num["$k"]/$v;
							$retention_ratio = sprintf("%.2f",$retention*100)."%";//新员工留用率完成比例
							$rate = $v/$plan_num;
							$achievement_ratio =sprintf("%.2f",$rate*100)."%";//13.89%招聘达成率完成比例
							$achievement_proportion = $this->Proportion($rate,0.6,0.8,0.9,0,50,70,100);//招聘达成率占比
							$retention_proportion = $this->Proportion($retention,0.4,0.6,0.8,0,50,80,100);//新员工留用率占比
					   		$department_arr = M("UserInfo")->field("department_id")->where(array('user_id'=>$k))->find();
					   		$list[$a]["user_id"] = $k;//招聘成功率完成比例
					   		$list[$a]["entry_num"] = $v;//实际入职人数
					   		$list[$a]["retention_num"] = $retention_num["$k"];//留用人数
					   		$list[$a]["department_id"] = $department_arr["department_id"];//招聘成功率完成比例
					   		$list[$a]["achievement_ratio"] = $achievement_ratio;//招聘成功率完成比例
					   		$list[$a]["achievement_proportion"] = $achievement_proportion;//招聘成功率占比
					   		$list[$a]["retention_ratio"] = $retention_ratio;//新员工留用率完成比例
					   		$list[$a]["retention_proportion"] = $retention_proportion;//招聘成功率占比
					   		$list[$a]["achievement_bonus"] = ($money * 0.8 * $achievement_proportion/100 + $money * 0.2 * $retention_proportion/100)."元";//招聘成功率占比
					   		$a++;
					   		$count++;
						}
				}else if($project==2){
						if(empty($start) || empty($money)){
							$result="";
							$this->error("方案二中绩效月份,项目总金额必填！");
							exit;
						}
						if(!empty($department_id)){
							if($department_id == 22){
								$result ="";
								$this->error("方案二只能用来考核非人资中心的！");
								exit();
							}
							if(!empty($plan_num)){
								$result ="";
								$this->error("方案二中不需要填写计划招聘人数！");
								exit();
							}
						  //每月的面试人数(含推荐并入职的人数)
							$interviewer_num = M("RecruitInfo")->where(array('created_at'=>array('like', I('get.start')."%"),'department_id'=>$department_id))
							->group("user_id")
							->getField('user_id,count(id) as count', true);
							//每月的入职人数
						$entry_num = M("RecruitInfo")->where(array('entry_date'=>array('like', I('get.start')."%"),'department_id'=>$department_id,'status'=>array('in', '1,2')))
						->group("user_id")
						->getField('user_id,count(id) as count', true);
						//每月的留用人数
						$retention_num = M("RecruitInfo")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'department_id'=>$department_id))
	                     ->group("user_id")
	                     ->getField('user_id, count(id) as count',true);
	                     //每月的内部推荐并入职的人数
							$recommend_num = M("RecruitInfo")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'department_id'=>$department_id,'info_sources'=>array('eq', 8),'status'=>array('eq', 1)))
		                     ->group("user_id")
		                     ->getField('user_id, count(id) as count',true); 

						}else{
							if(!empty($plan_num)){
								$result ="";
								$this->error("方案二中不需要填写计划招聘人数！");
								exit();
							}
		                     //每月的面试人数(包含推荐并入职的人数)
							$interviewer_num = M("RecruitInfo")->where(array('created_at'=>array('like', I('get.start')."%"),'department_id'=>array('neq', 22)))
							->group("user_id")
							->getField('user_id,count(id) as count', true);
							//每月的入职人数(包含推荐并入职的人数)
							$entry_num = M("RecruitInfo")->where(array('entry_date'=>array('like', I('get.start')."%"),'department_id'=>array('neq', 22),'status'=>array('in', '1,2')))
							->group("user_id")
							->getField('user_id,count(id) as count', true);
							//每月的留用人数(包含推荐并入职的人数)
							$retention_num = M("RecruitInfo")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'department_id'=>array('neq', 22)))
		                     ->group("user_id")
		                     ->getField('user_id, count(id) as count',true);
		                     //每月的内部推荐并入职的人数
							$recommend_num = M("RecruitInfo")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'department_id'=>array('neq', 22),'info_sources'=>array('eq', 8),'status'=>array('eq', 1)))
		                     ->group("user_id")
		                     ->getField('user_id, count(id) as count',true);    
						}
						$a = 0;
						$count = 0;
						foreach($entry_num as $k=>$v){
							$retention_num["$k"] = empty($retention_num["$k"])?0:$retention_num["$k"];
							$interviewer_num["$k"] = empty($interviewer_num["$k"])?0:$interviewer_num["$k"];
							$recommend_num["$k"] = empty($recommend_num["$k"])?0:$recommend_num["$k"];
							
							$retention = $retention_num["$k"]/$v;
							$retention_ratio = sprintf("%.2f",$retention*100)."%";//新员工留用率完成比例
							$retention_proportion = $this->Proportion($retention,0.4,0.6,0.8,0,50,80,100);//新员工留用率占比
							$success = $v/$interviewer_num["$k"];
							$success_ratio =sprintf("%.2f",$success*100)."%";//13.89%招聘成功率完成比例
							$success_proportion = $this->Proportion($success,0.3,0.5,0.8,0,40,70,100);//招聘达成率占比
							$recommend_proportion = $this->recommend($recommend_num["$k"]);//推荐并入职占比
					   		$department_arr = M("UserInfo")->field("department_id")->where(array('user_id'=>$k))->find();
					   		$list[$a]["user_id"] = $k;
					   		$list[$a]["entry_num"] = $v;//实际入职人数
					   		$list[$a]["interviewer_num"] = $interviewer_num["$k"];//实际面试人数
					   		$list[$a]["retention_num"] = $retention_num["$k"];//留用人数
					   		$list[$a]["department_id"] = $department_arr["department_id"];//
					   		$list[$a]["success_ratio"] = $success_ratio;//招聘成功率完成比例
					   		$list[$a]["success_proportion"] = $success_proportion;//招聘成功率占比
					   		$list[$a]["retention_ratio"] = $retention_ratio;//新员工留用率完成比例
					   		$list[$a]["retention_proportion"] = $retention_proportion;//招聘成功率占比
					   		$list[$a]["recommend_num"] = $recommend_num["$k"];//内部推荐并入职的人数
					   		$list[$a]["recommend_proportion"] = $recommend_proportion;//内部推荐人数占比
					   		$list[$a]["achievement_bonus"] = ($money * 0.5 * $success_proportion/100 + $money * 0.3 * $retention_proportion/100+$money * 0.2 * $recommend_proportion/100)."元";//绩效奖金
					   		$a++;
					   		$count++;
						}
				}else{
					$result="";
					$this->error("请选择绩效考核方案！");
					exit;
				}
			    break;
			    default :
			        if($user_department_id  == 22){
			        	if(empty($start) || empty($money) || empty($plan_num)  ){
			        		$this->error("绩效月份,项目总金额,计划招聘人数必须填写！");
			        		$result="";	
			        		exit();
						}
			        	if($user_department_id != 22   ){
			        		$result="";
			        		exit();
			        	}
			        	//每月的入职人数
						$entry_num = M("RecruitInfo")->field("count(id) as count")->where(array('entry_date'=>array('like', I('get.start')."%"),'user_id'=>$user_id,'status'=>array('in', '1,2')))->find();
						//每月的留用人数
						$retention_num = M("RecruitInfo")->field("count(id) as count")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'user_id'=>$user_id))->find();
						$rate = $entry_num["count"]/$plan_num;
						$achievement_ratio =sprintf("%.2f",$rate*100)."%";//招聘达成率完成比例
						$achievement_proportion = $this->Proportion($rate,0.6,0.8,0.9,0,50,70,100);//招聘达成率占比
						$retention = $retention_num["count"]/$entry_num["count"];
						$retention_ratio = sprintf("%.2f",$retention*100)."%";//新员工留用率完成比例
						$retention_proportion = $this->Proportion($retention,0.4,0.6,0.8,0,50,80,100);//新员工留用率占比
						$list["0"]["user_id"] = $user_id;
				   		$list["0"]["entry_num"] = $entry_num["count"];
				   		$list["0"]["retention_num"] = $retention_num["count"];//留用人数
				   		$list["0"]["department_id"] = $user_department_id;
				   		$list["0"]["achievement_ratio"] = $achievement_ratio;//招聘达成率完成比例
				   		$list["0"]["achievement_proportion"] = $achievement_proportion;//招聘达成率占比
				   		$list["0"]["retention_ratio"] = $retention_ratio;//新员工留用率完成比例
				   		$list["0"]["retention_proportion"] = $retention_proportion;//新员工留用率占比
				   		$list["0"]["achievement_bonus"] = ($money * 0.8 * $achievement_proportion/100 + $money * 0.2 * $retention_proportion/100)."元";//招聘成功率占比

			        }else{
			        	if(empty($start) || empty($money)   ){
			        		$result="";
			        		$this->error("绩效月份,项目总金额必须填写！");	
						}
			        	if( $department_id!=$user_department_id&&$department_id!=""   ){
							$result="";
							$this->error("您的权限不够，只能查看自己的部门！");
							exit;
						}
						//每月的面试人数(包含推荐并入职的人数)
						$interviewer_num = M("RecruitInfo")->field("count(id) as count")->where(array('created_at'=>array('like', I('get.start')."%"),'user_id'=>$user_id))->find();
						//每月的入职人数(包含推荐并入职的人数)
						$entry_num = M("RecruitInfo")->field("count(id) as count")->where(array('entry_date'=>array('like', I('get.start')."%"),'user_id'=>$user_id,'status'=>array('in', '1,2')))->find();
						//每月的留用人数
						$retention_num = M("RecruitInfo")->field("count(id) as count")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'user_id'=>$user_id))->find();
	                     //每月的内部推荐并入职的人数
						$recommend_num = M("RecruitInfo")->field("count(id) as count")->where(array('status'=>1,'entry_date'=>array('like', I('get.start')."%"),'user_id'=>$user_id,'info_sources'=>8))->find();
						$success = $entry_num["count"]/$interviewer_num["count"];//招聘成功率
						$success_ratio = sprintf("%.2f",$success*100)."%";//招聘成功率完成比例
						$success_proportion = $this->Proportion($success,0.3,0.5,0.8,0,40,70,100);//招聘达成率占比
						$retention = $retention_num["count"]/$entry_num["count"];
						$retention_ratio =sprintf("%.2f",$retention*100)."%";//新员工留用率比例
						$retention_proportion = $this->Proportion($retention,0.4,0.6,0.8,0,50,80,100);//新员工留用率占比
						$recommend_proportion = $this->Recommend($recommend_num["count"]);//推荐并入职占比
						$list["0"]["user_id"] = $user_id;
				   		$list["0"]["entry_num"] = $entry_num["count"];//实际入职人数
				   		$list["0"]["interviewer_num"] = $interviewer_num["count"];//实际面试人数
				   		$list["0"]["retention_num"] = $retention_num["count"];//留用人数
				   		$list["0"]["department_id"] = $user_department_id;
				   		$list["0"]["success_ratio"] = $success_ratio;//招聘成功率完成比例
				   		$list["0"]["success_proportion"] = $success_proportion;//招聘成功率占比
				   		$list["0"]["retention_ratio"] = $retention_ratio;//新员工留用率完成比例
				   		$list["0"]["retention_proportion"] = $retention_proportion;//招聘成功率占比
				   		$list["0"]["recommend_num"] = $recommend_num["count"];//内部推荐并入职的人数
				   		$list["0"]["recommend_proportion"] = $recommend_proportion;//内部推荐人数占比
				   		$list["0"]["achievement_bonus"] = ($money * 0.5 * $success_proportion/100 + $money * 0.3 * $retention_proportion/100+$money * 0.2 * $recommend_proportion/100)."元";//绩效奖金
			        }
			        $count = $interviewer_num==0?0:1;
			    	
			}
		    //$count = M("RecruitInfo")->field('count( distinct user_id) as count')->select();
		   // $result = array('list'=>$list, 'count'=>$count["0"]["count"]);
		    $result = array('list'=>$list, 'count'=>$count);
		    $this->ajaxReturn($result);
	}

	private function getDepartmentRow(){
		if (!isset($this->departmentRow)) {
			$this->departmentRow = D('Department')->find($this->getDepartmentId());
		}
		return $this->departmentRow;
	}

	private function isHrDeparment(){
		$this->getDepartmentRow();
		
		if ($this->departmentRow['type'] == DepartmentModel::HR_DEPARTMENT) {
			return true; //$_POST['department_id'] = 0;
		} else {
			return false; //$_POST['department_id'] = session('account')['userInfo']['department_id'];
		}
	}

	private function getDepartmentId(){
		// var_dump(session('account')['userInfo']['department_id']);
		if ($this->getRoleEname()=='gold') {
			return 0;
		} else {
			$depart_id = session('account')['userInfo']['department_id'];
			
			if ($depart_id == 0) {
				return 9999999;
			} else {
				return $depart_id;
			}
		}
		
	}

	

	private function setDeparmentQuery(){
		$departmentRow = $this->getDepartmentRow();
		$config = json_decode($departmentRow['config'], true);
		if (isset($config['EmployeeQueryCondition'])) {

			call_user_func(array($this, 'set'.$config['EmployeeQueryCondition']));
		}
	}



	private function setDepartmentEmployee(){
		
		$this->M->where(array(
			'user_info.department_id'=>array('eq', $this->getDepartmentId()),
			// 'role_id'=>array('NEQ', array()) 
		));

	}
	private function setAllEmployee(){
		
	}
	// 
	private function goldCondition(){
		$this->setAllEmployee();
	}

	//人事
	private function humanResourceCondition(){

		if ($this->isHrDeparment()) {
			$this->setAllEmployee();
		} else {
			$this->setDeparmentQuery();
		}
		
	}

	//人事经理
	private function hrMasterCondition(){
		$this->setAllEmployee();
	}

	//风控经理
	private function riskMasterCondition(){
		$this->setDepartmentEmployee();
	}
	//客服经理
	private function serviceMasterCondition(){
		$this->setDepartmentEmployee();
	}



	//部门经理
	private function departmentMasterCondition(){
		$this->setDepartmentEmployee();
	}


	public function setRoleCondition(){
		$this->roleEname = $this->getRoleEname();
        $funcName = $this->roleEname."Condition";
        if (method_exists($this, $funcName)) {
             call_user_func(array($this, $funcName));
        } else {
        	$this->error("没有权限EmployeeController");
        }
	}

	



	public function getRoles(){
		/*$row = M('rbac_role')->field('level')->find(session('account')['userInfo']['role_id']);
		return D('rbac_role')->where(array('level'=>array('gt', $row['level'])))->select();*/
		$departRow = D("Department")->find(session('account')['userInfo']['department_id']);
		if ($departRow) {
			return D("Department")->getEmployeeRoles($departRow['type']);
		} else {
			return D('rbac_role')->select();
		}
		
	}


	/**
	* 获取用户 角色 id
	*
	*/
	public function getUserRoles(){
		$result = D('rbac_role_user')->where(array('user_id'=> I('get.user_id',0)))->select();
		$this->ajaxReturn($result);
	}

	/**
	* 设置用户 角色 id
	*/
	public function setUserRoles(){
		$M = D('rbac_role_user');
		$user_id = I('post.user_id',0);
		$role_ids = I('post.role_ids');
		$insert_list = array();
		if (is_array($role_ids)) {
			foreach ($role_ids as $value) {
				$insert_list[] = array('role_id'=>$value, 'user_id'=>$user_id);
			}
		} else {
			$insert_list[] = array('role_id'=>$role_ids, 'user_id'=>$user_id);
		}
		
		$M->startTrans(); 
		$result = $M->where(array('user_id'=>$user_id))->delete();

		if ($result !== false) {
			$insert_result = $M->addAll($insert_list);
			if ($insert_result !== false) {
				$re = M('user_info')->data(array('user_id'=>$user_id, 'role_id'=>$role_ids))->save();
				if ($re !== false) {
					$M->commit();
					$this->success("操作成功");
				} else {
					$M->rollback();
					$this->error("操作失败".M('user_info')->getError());
				}
				
			} else {
				$M->rollback();
				$this->error("操作失败".$M->getError());
			}
		} else {
			$M->rollback();
			
			$this->error("操作失败".$M->getError());
		}
	}

	/**
	* 预处理
	*/
	public function _before_add(){
		$this->rightProcted();	
	}

	/**
	* 添加
	*/
	public function add(){
		$_POST["graduation_date"] = UTC_to_locale_time($_POST["graduation_date"]);
		$_POST["resume_entry_date"] = UTC_to_locale_time($_POST["resume_entry_date"]);
		$_POST["interviewer_date"] = UTC_to_locale_time($_POST["interviewer_date"]);
	    $_POST["recruit_type"] = 1;
	    $_POST['department_id'] = session('account')['userInfo']['department_id'];
	    $_POST['user_id'] = session('account')['userInfo']['user_id'];
		/*if(session('account')['userInfo']['department_id']!=0){
			$_POST['department_name'] =D("Department")->getDepartment(session('account')['userInfo']['department_id']);	
		}*/
		$re = $this->M->create($_POST, 1);
		if ($re) {
			$this->M->startTrans(); 
			$re['recruitInfo'] = M('recruitInfo')->create($_POST, 1);
			$id = $this->M->add($re);
			if ($id) {
					$this->M->commit();
					$this->success(L('ADD_SUCCESS'));
			} else {
				$this->M->rollback();
				$this->error($this->M->getError());
			}
		} else {
			$this->error($this->M->getError());
		}

	}



	/**
	* 编辑
	*/
		public function edit(){
		//新方法
		
		$_POST["graduation_date"] = UTC_to_locale_time($_POST["graduation_date"]);
		$_POST["resume_entry_date"] = UTC_to_locale_time($_POST["resume_entry_date"]);
		$_POST["interviewer_date"] = UTC_to_locale_time($_POST["interviewer_date"]);
        $re = M('recruitInfo')->create($_POST, 2);
		if ($re) {
			if (M('recruitInfo')->where(array('id'=>I('post.id') ))->save() !== false) {
				$this->success(L('ADD_SUCCESS'));
			} else {
				$this->error($this->M->getError().$this->M->getLastSql());
			}
		} else {
			$this->error($this->M->getError().$this->M->getLastSql());
		}

	}


	public function changePassword(){
		$re = $this->M->create($_POST, 2);
		if ($re) {
			if ($this->M->save() !== false) {
				$this->success(L('ADD_SUCCESS'));
			} else {
				$this->error($this->M->getError().$this->M->getLastSql());
			}
		} else {
			$this->error($this->M->getError().$this->M->getLastSql());
		}
	}

	public function setEmployeeDepartemtnItem(){
		if ($this->getRoleEname()=='gold') {
			return 1;
		} else if(session('account')['userInfo']['department_id']!=0){
			$row = $this->getDepartmentRow();
			if ($row['type']==DepartmentModel::HR_DEPARTMENT) {
				return 1;
			} 
		}
		return 0;
	}
	public function departmentId($department_id){
		if($department_id !=22){
			$result = "".exit();
			return $result;
		}

	}
	public function Proportion($rate,$a,$b,$c,$aa,$bb,$cc,$dd){
			if($rate<$a){
	   			$proportion = ($aa)."%";
	   		}else if( $a <= $rate&&$rate < $b ){
	   			$proportion = ($bb)."%";
	   		}else if($b<=$rate&&$rate<$c){
	   			$proportion = ($cc)."%";
	   		}else if($c<=$rate){
	   			$proportion = ($dd)."%";
	   		}
   		return $proportion;

	}
	public function Recommend($recommend_num){
		if($recommend_num<1){
			$recommend_proportion = (0)."%";
		}else if(1<=$recommend_num&&$recommend_num <=5){
   			$recommend_proportion = (50)."%";	
   		}else{
   			$recommend_proportion = (100)."%";
   		}
   		return $recommend_proportion;

	}








}
